<?php
if($levelTL != 3) {
	die("Bạn không đủ quyền để truy cập trang này!");
}
	$num		= FILM_PAGE_ADMIN;
	$num 		= intval($num);
	$page 		= intval($page);
	if (!$page) $page = 1;
	$limit 		= ($page-1)*$num;
	if($limit<0) $limit=0;
	
	if($_GET["phimid"]) {
		$phimid	=	(int)$_GET["phimid"];
		$where	=	"phimid = '$phimid'";
		$urlpg	=	"&phimid=$phimid";
	}else {
		$where	=	"camnhanid != 0";
	}
?>
	<div class="content_block">
		<div class="form_tbl" id="slides">
			
		
				<span class="border_d clearfix">
                <h1 style="padding: 16px 0px 16px 0px;">Danh sách bình luận phim</h1>
                <form name="media_list" method="post" onSubmit="return check_checkbox();">
                		<table cellpadding="0" cellspacing="0" width="100%">
                        	<tr>
                            <td class="form_item" width="10" align="center">
<input style="width:10px;" type="checkbox" name="chkall" id="chkall" onclick="docheck(document.media_list.chkall.checked,0)" value="checkall">
                            </td>
                            <td class="form_item" align="left">Phim / Tên tài khoản/ Nội dung bình luận</td>
                            </tr>
<?php
$arr		=	$db->database("*","comment","$where ORDER BY camnhanid DESC LIMIT $limit,$num");
$total		=	$db->database("camnhanid","comment","$where  ORDER BY camnhanid DESC");
$total		=	count($total);
$pagehtml 	= 	ipos_pages($total,$num,$page,"index.php?ipos=comment$urlpg&p=");
if($arr) {
	for($i=0;$i<count($arr);$i++) {
		$username	=	get_data("user","username","userid = '".$arr[$i][2]."'");
		$filmname	=	get_data("film","tenphim","phimid = '".$arr[$i][1]."'");
		$filmurl	=	url_link($filmname,$arr[$i][1],"phim");
		if (!$filmname) { 
			$filmname = 'Bài hát có ID là: '.en_id($arr[$i][1]);
		}
?>
                        	<tr>
                            	<td class="form_item" align="center">
<input style="width:10px;" class="checkbox" type="checkbox" id="checkbox" onclick="docheckone()" name="checkbox[]" value="<?=$arr[$i][0];?>">
                            	</td>
                            	<td class="form_item" align="left">
                                	<a target="_blank" href="<?=MAIN_URL?>/nghe-bai-hat/Song/<?=en_id($arr[$i][1])?>.html"><?=$filmname;?></a><br />
									<strong><?=$username;?></strong>: <?=un_htmlchars($arr[$i][4]);?><br />
                            	</td>
                            </tr>
<? } 
}else {
	?>
                        	<tr>
                            	<td class="form_item" colspan="2" align="left">
									Chưa có bình luận nào!
                            	</td>
                            </tr>
    <?
}?>
							<tr><td class="form_item" colspan="2" style="text-align: right;"><ul class="pages"><?=$pagehtml;?></ul></td></tr>
                            <tr><td class="form_item" colspan="2">
                            	Với những yêu cầu đã chọn: 
                                    <select style="width: 150px;" name="selected_option">
                                        <option value="xoa">Xóa</option>
        							</select>

        						<input style="width: 70px; cursor:pointer;" type="submit" name="do" class=submit value="Thực hiện">
                            </td></tr>
                        </table>
                        
                        </form>
				</span>

			</div>
		</div>
<script>
function ask(){
	if (confirm("Bạn có chắc chắn muốn xóa bộ phim này")) return true;
	return false ;
}
</script>
<?php
if ($_POST['do']) {
	$arr = $_POST['checkbox'];
	if (!count($arr)) die('Lỗi');
	$in_sql = implode(',',$arr);
	// xóa
	if ($_POST['selected_option'] == 'xoa') {
		$db->dbdelete("comment","camnhanid IN (".$in_sql.")");
		header("Location: index.php?ipos=comment");
	}
	exit();
}
?>